package de.tum.in.eist.im.client;

import java.util.LinkedList;
import java.util.List;
import de.tum.in.eist.im.client.domain.*;

/**
 * The {@link ClientModel} class holds all information about the data to be
 * displayed by the {@link ClientView} class.
 * 
 * @author Christian Ivicevic (ga73yis@mytum.de)
 * @since 08-31-2011
 * @version 08-31-2011
 */
public class ClientModel {
	/**
	 * Holds a {@link List} of all users, represented by {@link User} objects,
	 * which are currently online. Usually updated via a push notification of
	 * the server.
	 */
	private List<User> userList = null;
	/**
	 * Holds a {@link List} of all messages, represented by {@link Message}
	 * objects, received during the current session. Usually updated via a push
	 * notification of the server.
	 */
	private List<Message> messageList = null;
	/**
	 * Holds information on the {@link User} currently logged in to the system.
	 */
	private User currentUser = null;
	/**
	 * Boolean value indicating whether the current user is logged in.
	 */
	private boolean loggedIn = false;

	/**
	 * Creates a new instance of the {@link ClientModel} class.
	 */
	public ClientModel() {
		this.userList = new LinkedList<User>();
		this.messageList = new LinkedList<Message>();
	}

	/**
	 * This method is used by the {@link ClientController} to update the model
	 * contents by pushing a new {@link List} of {@link User}s to it.
	 * 
	 * @param userList
	 *            the list of the {@link User}s who are currently online
	 */
	public void pushNewUserList(List<User> userList) {
		this.userList = userList;
	}

	/**
	 * Adds a new {@link Message} to the collection.
	 * 
	 * @param message
	 *            the {@link Message} to add to the collection.
	 */
	public void addNewMessage(Message message) {
		this.messageList.add(message);
	}

	/**
	 * @return the userList
	 */
	public List<User> getUserList() {
		return this.userList;
	}

	/**
	 * @return the messageList
	 */
	public List<Message> getMessageList() {
		return this.messageList;
	}

	/**
	 * @return the currentUser
	 */
	public User getCurrentUser() {
		return this.currentUser;
	}

	/**
	 * Sets the current user.
	 */
	public void setCurrentUser(User currentUser) {
		this.currentUser = currentUser;
	}

	/**
	 * Returns a boolean value indicating whether the current user is logged in.
	 * 
	 * @return true, if the current user is logged in; otherwise, false.
	 */
	public boolean isLoggedIn() {
		return this.loggedIn;
	}

	/**
	 * Sets the login value to the specified one.
	 * 
	 * @param isLoggedIn
	 *            boolean value indicating whether the current user should be
	 *            marked as logged in.
	 */
	public void setLoggedIn(boolean isLoggedIn) {
		this.loggedIn = isLoggedIn;
	}
}